﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Control.Bus;

namespace Control.Dal
{
    class DalExportBill
    {
        internal static List<Control.Bus.BusExportBill> GetByStaff(Control.Bus.BusStaff staff)
        {
            var bills = from b in DalCommon.Database.ExportBills
                        where b.IDStaff == staff.ID
                        select new BusExportBill
                        {
                            ID = b.ID,
                            Date = (DateTime)b.Date,
                            Staff = staff,
                            BillCode=b.BillCode,
                            BillName=b.BillName
                        };
            return bills.ToList<BusExportBill>();
        }

        internal static int Insert(BusExportBill busExportBill)
        {
            ExportBill Bill = new ExportBill()
            {
                IDStaff = busExportBill.Staff.ID,
                Date = busExportBill.Date,
                BillCode=busExportBill.BillCode,
                BillName=busExportBill.BillName,
            };
            DalCommon.Database.ExportBills.InsertOnSubmit(Bill);
            DalCommon.Database.SubmitChanges();
            return Bill.ID;
        }


        internal static void UpDate(BusExportBill busExportBill)
        {
            WareHouseDataContext db = DalCommon.Database;
            ExportBill Bill = db.ExportBills.Single(b => b.ID == busExportBill.ID);
            Bill.IDStaff = busExportBill.Staff.ID;
            Bill.Date = busExportBill.Date;
            Bill.BillCode = busExportBill.BillCode;
            Bill.BillName = busExportBill.BillName;
            db.SubmitChanges();
        }


    }
}
